<!DOCTYPE html>
<html>
<head>
    <title>首页</title>
    <#include "head.ftl"/>
    <script type="text/javascript" src="/js/md5.min.js"></script>
    <script type="application/javascript">
        /***/
        if (window != top) {
            window.parent.location.href = window.location.href;
        }
    </script>
</head>
<body style="background-color: #f2f2f2">
<form class="layui-form" action="">
    <div class="layui-row login">
        <div class="layui-col-md12 title">
            <i class="layui-icon layui-icon-app"></i>
            <span style="font-size: 24px;">JRapider管理平台</span>
        </div>
        <div class="layui-col-md12 layui-form-pane">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input name="loginId" lay-verify="required" autocomplete="off" type="text" class="layui-input"/>
            </div>
        </div>
        <div class="layui-col-md12 layui-form-pane">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input name="password" lay-verify="required" autocomplete="off" type="password" class="layui-input"/>
            </div>
        </div>
        <div class="layui-col-md12 layui-form-pane">
            <label class="layui-form-label">验证码</label>
            <div class="layui-input-inline">
                <input name="code" lay-verify="required" autocomplete="off" type="text" class="layui-input"/>
                <img id="kaptcha" src="/kaptcha">
            </div>
        </div>
        <div class="layui-col-md12 layui-form-pane">
            <button type="submit" class="layui-btn layui-btn-ms" lay-submit>登录</button>
        </div>
    </div>
</form>
<div class="footer">
    Copyright © 2018 JRapider
</div>
<script type="application/javascript">
    $("#kaptcha").on("click", function () {
        $(this).attr("src", $(this).attr("src"));
    });
    layui.use(['element', 'form'], function () {
        var form = layui.form;
        //自定义验证规则
        form.verify(verify_rule);
        //监听提交
        form.on('submit', function (data) {
            data.field["password"] = md5(data.field["password"]);
            $.ajax({
                url: "/data/login",
                dataType: "json",
                method: "POST",
                data: data.field,
                complete: function () {
                    $("#kaptcha").click();
                },
                success: function (result) {
                    if (result.code > 0) {
                        layer.msg(result.msg, {
                            time: 1
                        }, function () {
                            window.location.href = "/";
                        });
                    } else {
                        layer.alert(result.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>